//
// Created by xili on 2024/9/27 15:20.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    vector<int> getAverages(vector<int> &nums, int k) {
        int n = nums.size();
        vector<int> ans(n, -1);
        int cnt = 2 * k + 1;
        if (n < cnt) {
            return ans;
        }
        long long sum = 0;
        for (int i = 0; i < cnt - 1; i++) {
            sum += nums[i];
        }
        for (int i = k; i < n - k; i++) {
            sum += nums[i + k];
            ans[i] = sum / cnt;
            sum -= nums[i - k];
        }
        return ans;
    }
};